﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Asplode.GameEntity.Characters;
using Asplode.Events;

namespace Asplode.GameWorld
{
    public class GameWorldEventHandler :
                BoxSpawnEventHandler,
                GameWorld_InitializeGameEventHandler,
                HumanSpawnEventHandler,
                RemoveEntityEventHandler,
                ZombieSpawnEventHandler
    {

        private GameWorld GameWorld;
        public GameWorldEventHandler(GameWorld gw)
        {
            GameWorld = gw;
        }


        public void handle(BoxSpawnEvent t)
        {
            GameWorld.EntList.Add(t.Box);
        }
        public void handle(GameWorld_InitializeGameEvent t)
        {
            GameWorld.ClearWorld();
            GameWorld.Initialize();
        }
        public void handle(HumanSpawnEvent t)
        {
            GameWorld.EntList.Add(t.entity);
        }
        public void handle(RemoveEntityEvent t)
        {
            foreach (Human player in GameWorld.Humans)
            {
                if (player.gameObject.body == t.entity)
                {
                    GameWorld.Humans.Remove(player);
                }
            }
            foreach (Zombie zombie in GameWorld.Zombies)
            {
                if (zombie.gameObject.body == t.entity)
                {
                    GameWorld.Zombies.Remove(zombie);
                }
            }
            if (GameWorld.EntList.Contains(t.entity))
            {
                GameWorld.EntList.Remove(t.entity);
            }

        }
        public void handle(ZombieSpawnEvent zse)
        {
            GameWorld.EntList.Add(zse.entity);
        }
    }
}
